/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.me.stepapp;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AnalogClock;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import org.me.stepapp.persistence.InsertLocation;
import org.me.stepapp.persistence.ListLocation;

/**
 *
 * @author Amber
 */
public class LocationActivity extends TabActivity {

    /* Action when onStart is called */
    @Override
    public void onStart()  {
        super.onRestart();
        Toast.makeText( this,"onStart", Toast.LENGTH_SHORT);
    }

    /* Action when onRestart is called */
    @Override
    public void onRestart()  {
            super.onRestart();
              Toast.makeText( this,"onRestart", Toast.LENGTH_SHORT);
    }

    /* Action when onResume is called */
    @Override
    public void onResume()  {
        super.onResume();
        Toast.makeText( this,"onResume", Toast.LENGTH_SHORT);
    }

    // Declare intents
    Intent insertLocationIntent;
    Intent listLocationIntent;
    Intent displayMapIntent;

    //  Create TabHost
    TabHost tabs;

    /* Action when onCreate is called */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.location_activity);
        tabs = getTabHost();

        insertLocationIntent = new Intent(this,InsertLocation.class );
        listLocationIntent = new Intent(this,ListLocation.class );
        displayMapIntent = new Intent(this, DisplayMap.class);

        addTab( "Location List", listLocationIntent );
        addTab( "Add Location", insertLocationIntent );
        addTab( "Display Map", displayMapIntent);

        // Tabs event change
        tabs.setOnTabChangedListener( new OnTabChangeListener() {
            public void onTabChanged(String arg0) {
                Toast.makeText(LocationActivity.this, "" + arg0, Toast.LENGTH_SHORT).show();
                //setCurrentTab(  tabs.getCurrentTab(), arg0 );
                tabs.getCurrentTabView().refreshDrawableState();
            }
         });
    }

    /* Add a tab with name <name> and a clock */
    void addTab( String name )    {
        TabHost.TabSpec spec=tabs.newTabSpec(name);
        spec.setContent(new TabHost.TabContentFactory() {
            public View createTabContent(String tag) {
                return(new AnalogClock(LocationActivity.this));
                }
            });
        spec.setIndicator(name);
        tabs.addTab(spec);
    }


    /* Add a tab with name <name> using given layout */
    void addTab( String name , int layoutId )   {
       tabs.addTab(tabs.newTabSpec(name).setIndicator(name).setContent(layoutId));

    }

    /* add a tab with name <name> and a clock using an intent */
    void addTab( String name, Intent intent )  {
        tabs.addTab(tabs.newTabSpec(name).setIndicator(name).setContent(intent));
    }

    /* Set current tab */
    void setCurrentTab( int tab, String title)  {
          //TextView current_text = (TextView)findViewById( R.id.tab);
          //current_text.setText("" + tab + "(" + title + ")" );
    }

}
